package it.zqdszb.mvp.modelImp;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import it.zqdszb.entity.HotChannelBean;
import it.zqdszb.entity.PlayLinkListBean;
import it.zqdszb.library.api.HttpPostService;
import it.zqdszb.library.api.entitys.BaseResult;
import it.zqdszb.library.basemvp.BaseModeImpl;
import it.zqdszb.library.retrofit.exception.ApiException;
import it.zqdszb.mvp.callback.OnGetPlayLinkCallBack;
import it.zqdszb.mvp.callback.OnTvRecommendCallBack;
import it.zqdszb.mvp.contract.TvRecommendContract;

/**
 * Created by GH on 2018-05-13.
 */

public class TvRecommendModeImp  extends BaseModeImpl implements TvRecommendContract.TvRecommendModel{
	OnTvRecommendCallBack callBack;

	OnGetPlayLinkCallBack playLinkCallBack;

	@Override
	public void fetchData(OnTvRecommendCallBack callBack) {
		this.callBack=callBack;

		sendPost(HttpPostService.getLiveHotChannel, null, HotChannelBean.class, true, false, null);
	}

	@Override
	public void getPlayLink(OnGetPlayLinkCallBack callBack, String channerlId) {
		this.playLinkCallBack=callBack;
		Map<String, Object> params = new HashMap<>();
		params.put("channerlId",channerlId);
		sendPost(HttpPostService.getChannelPlayLink, params, PlayLinkListBean.class, true, false, null);

	}

	@Override
	public void onNext(BaseResult result) {

		if(result.getMethod()==HttpPostService.getLiveHotChannel){
			callBack.onSuccess((List<HotChannelBean>)result.getResult());
		}

		if(result.getMethod()==HttpPostService.getChannelPlayLink){
			playLinkCallBack.onSuccessPlayLink((List<PlayLinkListBean>)result.getResult());
		}
	}

	@Override
	public void onError(ApiException e, String mothead) {
		super.onError(e, mothead);

		if(mothead==HttpPostService.getLiveHotChannel){
			callBack.onFailed(mothead);
		}

		if(mothead==HttpPostService.getChannelPlayLink){
			playLinkCallBack.onFailedPlayLink(mothead);
		}


	}
}
